
package kaizone.haining.chaobohui.args;

import kaizone.haining.chaobohui.json.BannerDO;
import kaizone.haining.chaobohui.json.Item;
import kaizone.haining.chaobohui.json.UserRegister;
import kaizone.haining.chaobohui.login.User;
import android.content.Context;
import android.content.SharedPreferences;
import android.sax.TextElementListener;
import android.text.TextUtils;

public class AppArgs {

    public final static String APP_TABLE = "caobohui";

    public final static String APP_START = "app_start";

    public static void writeStartApp(Context cotext, int count) {
        SharedPreferences apptable = cotext.getSharedPreferences(APP_TABLE, 0);
        apptable.edit().putInt(APP_START, count).commit();
    }

    public static int readStartAppCount(Context context) {
        SharedPreferences apptable = context.getSharedPreferences(APP_TABLE, 0);
        int count = apptable.getInt(APP_START, 0);
        return count;
    }
    
    public final static String USER_TABLE = "chaobohui_users";
    
    public static void writeUserInfo(Context cotext, UserRegister register) {
        SharedPreferences apptable = cotext.getSharedPreferences(USER_TABLE, 0);
        apptable.edit().putString(UserRegister.AUTHKEY, register.authKey).commit();
        apptable.edit().putString(UserRegister.CHECKINACTIVITYCOUNT, register.checkinActivityCount).commit();
        apptable.edit().putString(UserRegister.FAVORITESUBJECTCOUNT, register.favoriteSubjectCount).commit();
        apptable.edit().putString(UserRegister.FOLLOWACTIVITYCOUNT, register.followActivityCount).commit();
        apptable.edit().putString(UserRegister.GMTAUTH, register.gmtAuth).commit();
        apptable.edit().putString(UserRegister.GMTCREATE, register.gmtCreate).commit();
        apptable.edit().putString(UserRegister.GMTMODIFIED, register.gmtModified).commit();
        apptable.edit().putInt(UserRegister.USERID, register.userId).commit();
        apptable.edit().putString(UserRegister.MD5PASSWORD, register.md5Password).commit();
        apptable.edit().putString(UserRegister.REGISTERIMEI, register.registerIMEI).commit();
        apptable.edit().putString(UserRegister.USERNAME, register.userName).commit();
    }
    
    public static UserRegister readUserInfo(Context cotext) {
    	SharedPreferences apptable = cotext.getSharedPreferences(USER_TABLE, 0);
    	UserRegister register = new UserRegister();
    	register.authKey = apptable.getString(UserRegister.AUTHKEY, null);
    	register.checkinActivityCount = apptable.getString(UserRegister.CHECKINACTIVITYCOUNT, null);
    	register.favoriteSubjectCount = apptable.getString(UserRegister.FAVORITESUBJECTCOUNT, null);
    	register.followActivityCount = apptable.getString(UserRegister.FOLLOWACTIVITYCOUNT, null);
    	register.gmtAuth = apptable.getString(UserRegister.GMTAUTH, null);
    	register.gmtCreate = apptable.getString(UserRegister.GMTCREATE, null);
    	register.gmtModified = apptable.getString(UserRegister.GMTMODIFIED, null);
    	register.userId = apptable.getInt(UserRegister.USERID, 0);
    	register.md5Password = apptable.getString(UserRegister.MD5PASSWORD, null);
    	register.registerIMEI = apptable.getString(UserRegister.REGISTERIMEI, null);
    	register.userName = apptable.getString(UserRegister.USERNAME, null);
    	return register;
    }
    
    public static boolean isReadUserInfo(Context cotext){
    	UserRegister register = readUserInfo(cotext);
    	if(TextUtils.isEmpty(register.userName))
    		return true;
    	if(TextUtils.isEmpty(register.authKey))
    		return true;
    	return false;
    	
    }

    public static Item sNearbyItem;
    
    public static BannerDO sBannerDO;

    public static int sLocateAble = 0;
}
